package C059;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * ClassName: c02_02
 * Package: C059.graph
 * Description:【模板】拓扑排序  牛客网https://www.nowcoder.com/practice/88f7e156ca7d43a1a535f619cd3f495c
 * 邻接表 - 动态模版
 * @Author BCXJ
 * @Create 2025/10/10 08:41
 * @Version 1.0
 * @Since 1.0
 */
public class c02_02 {
    

    /*
    17 16
    11 6
    7 6
    16 7
    2 16
    14 11
    10 2
    4 6
    5 7
    15 5
    17 15
    8 6
    9 11
    12 4
    13 9
    1 11
    3 8

     */
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        n = scanner.nextInt();
        m = scanner.nextInt();
        int[][] arr = new int[m][2];
        for (int i = 0; i < m; i++) {
            arr[i][0] = scanner.nextInt();
            arr[i][1] = scanner.nextInt();
        }
        int[] res = findOrder(arr);
        if(res == null) {
            System.out.println(-1);
        } else {
            for (int i = 0; i < res.length - 1; i++) {
                System.out.print(res[i] + " ");
            }
            System.out.print(res[res.length - 1]);
        }
    }
    // 点数 与 边数
    static int n , m;
    // 图
    static List<List<Integer>> grap = new ArrayList<>();
    // 队列
    static int[] queue;
    static int l, r;
    static int[] indegree; // 入度表
    private static int[] findOrder(int[][] arr) {
        // 初始化
        // 初始化图
        grap.clear();
        for (int i = 0; i < n + 1; i++) {
            grap.add(new ArrayList<>());
        }
        queue = new int[n + 1];
        l = r = 0;
        indegree = new int[n + 1];
        // 建图
        for (int i = 0; i < arr.length; i++) {
            addEdge(arr[i][0], arr[i][1]);
        }
        // 入度统计
        for (int i = 1; i <= n; i++) {
            if(indegree[i] == 0) {
                queue[r ++] = i;
            }
        }
        // 计算结果
        int[] res = new int[n];
        int count = 0;
        while(l < r) {
            int curNode = queue[l ++];
            res[count ++] = curNode;
            List<Integer> edges = grap.get(curNode);
            for (int i = 0; i < edges.size(); i++) {
                indegree[edges.get(i)] --;
                if(indegree[edges.get(i)] == 0) {
                    queue[r ++] = edges.get(i);
                }
            }
        }
        return count != n ? null : res;
    }

    // 加边
    private static void addEdge(int from, int to) {
        grap.get(from).add(to);
        indegree[to] ++;
    }
}
